package flysearch.ui;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.ext.swing.SwingButton;
import javafx.ext.swing.SwingLabel;
import javax.swing.JFileChooser;

var searchButton: SwingButton;
var pathLabel: SwingLabel;
var fileChooser: JFileChooser;
var mainStage: Stage;

var indexPath: String;

searchButton = SwingButton {
    translateX: 10
    translateY: 50
    width: 100
    height: 40
    text: "Set Path!"
    action: function() {
        if (fileChooser == null) {
            fileChooser = JFileChooser {};
            fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        }
        if (fileChooser.showOpenDialog(null) == javax.swing.JFileChooser.APPROVE_OPTION) {
            indexPath = fileChooser.getSelectedFile().toURI().toString();
            pathLabel.text = indexPath;
        }
    }
}

pathLabel = SwingLabel {
    translateX: 10
    translateY: 10
    text: "You need to set path first"
}

mainStage = Stage {
    title: "Setting your desktop search engine"
    width: 600
    height: 196
    scene: Scene {
        content: [
            searchButton,
            pathLabel
        ]
    }
}